package com.block.merchant.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.block.common.constant.AppRspCodeConstant;
import com.block.common.vo.ResponseVo;
import com.block.db.entity.MerchantProductLaunchInfo;
import com.block.db.mapper.MerchantProductLaunchMapper;
import com.block.merchant.service.IMerchantProductLaunchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class MerchantProductLaunchServiceImpl extends ServiceImpl<MerchantProductLaunchMapper,MerchantProductLaunchInfo> implements IMerchantProductLaunchService {

    @Autowired
    MerchantProductLaunchMapper merchantProductLaunchMapper;

    @Override
    public ResponseVo getMerchantProductLaunchList() {
        JSONObject returnData = new JSONObject();
        List<MerchantProductLaunchInfo> merchantProductLaunchInfoList = merchantProductLaunchMapper.getMerchantProductLaunchList();

        returnData.put("list",merchantProductLaunchInfoList);
        return new ResponseVo(AppRspCodeConstant.SUCCESS, returnData);
    }

    @Override
    public ResponseVo getOverList(String listIds) {
        JSONObject returnData = new JSONObject();
        List<MerchantProductLaunchInfo> merchantProductLaunchInfoList;
        if(listIds == null){
            returnData.put("list",returnData);
        }
        if (listIds.contains(",")) {
            List<Long> idList = Arrays.stream(listIds.split(","))
                    .map(Long::valueOf)
                    .collect(Collectors.toList());
            merchantProductLaunchInfoList = merchantProductLaunchMapper.getOverList(idList);
        } else {
            List<Long> idList = Arrays.asList(Long.valueOf(listIds));
            merchantProductLaunchInfoList = merchantProductLaunchMapper.getOverList(idList);
        }
        returnData.put("list",merchantProductLaunchInfoList);
        return new ResponseVo(AppRspCodeConstant.SUCCESS, returnData);
    }
}
